<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>东财个股资金流</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			p {margin:5px}
			ul {margin:1px}			
			h4 {margin:1px}	
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
			width:1000px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			var bkcolor = $("body").css("backgroundColor");
			window.onload = function() {			
				getSource(1);
				changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource(y);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
						
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "100%";	
				//obj1.style.height= "620px";		
				obj1.style.fontSize="12px";						
			}	
						
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
										
			var trid = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background=bkcolor;
							}else{
								this.style.background="#483D8B";
							}
						}						
					}					
				}
			}			
			
			function NumberTransform(num) { 
				var result = num;
				if(Math.abs(num) > 100000000){
					result = num / 100000000;
					result = result.toFixed(2) + "亿";
				}else if(Math.abs(num) > 10000){
					result = num/10000;
					result = result.toFixed(2) + "万";
				}				   
				return result;  
			};	
			
			var fid = "";
			var rs = 3;  //默认主力净额高亮
			var fx = 1;
			var y = 0;			
			function getSource(s) {			    
				if(s != 0){
					y = s
				}
				div = document.getElementById('towrite');								
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getSource(" + "\"1\"" + ")'>" + "当日" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px3' onclick='getSource(" + "\"3\"" + ")'>" + "3日" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='px5' onclick='getSource(" + "\"5\"" + ")'>" + "5日" + "</a>";
				var p4 = "<a href='javascript:void(0)' id='px10' onclick='getSource(" + "\"10\"" + ")'>" + "10日" + "</a>";
				div.innerHTML = "<font size='3'>东财个股资金流" + "<font size='2'> （" + p1 + p2 + p3 + p4 + "）</font></font>";
				
				aObj = document.getElementById('px' + y);				
				aObj.innerText = aObj.innerText;
				aObj.style.color = "#FFA07A";				
				
				var u1 = "f12,f14,f3,f62,f184,f66,f69,f72,f75,f78,f81,f84,f87"; 
				var u3 = "f12,f14,f127,f267,f268,f269,f270,f271,f272,f273,f274,f275,f276"; 
				var u5 = "f12,f14,f109,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173"; 
				var u10 = "f12,f14,f160,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183"; 
				if(y == 1){
					u = u1;
					if(rs == 2){
						fid = "f3";
					}else if(rs == 3){
						fid = "f62";
					}else if(rs == 4){
						fid = "f184";
					}else if(rs == 5){
						fid = "f66";
					}else if(rs == 6){
						fid = "f69";
					}else if(rs == 7){
						fid = "f72";
					}else if(rs == 8){
						fid = "f75";
					}else if(rs == 9){
						fid = "f78";
					}else if(rs == 10){
						fid = "f81";
					}else if(rs == 11){
						fid = "f84";
					}else if(rs == 12){
						fid = "f87";
					}
				}else if(y == 3){
					u = u3;
					if(rs == 2){
						fid = "f127";
					}else if(rs == 3){
						fid = "f267";
					}else if(rs == 4){
						fid = "f268";
					}else if(rs == 5){
						fid = "f269";
					}else if(rs == 6){
						fid = "f270";
					}else if(rs == 7){
						fid = "f271";
					}else if(rs == 8){
						fid = "f272";
					}else if(rs == 9){
						fid = "f273";
					}else if(rs == 10){
						fid = "f274";
					}else if(rs == 11){
						fid = "f275";
					}else if(rs == 12){
						fid = "f276";
					}
				}else if(y == 5){
					u = u5;
					if(rs == 2){
						fid = "f109";
					}else if(rs == 3){
						fid = "f164";
					}else if(rs == 4){
						fid = "f165";
					}else if(rs == 5){
						fid = "f166";
					}else if(rs == 6){
						fid = "f167";
					}else if(rs == 7){
						fid = "f168";
					}else if(rs == 8){
						fid = "f169";
					}else if(rs == 9){
						fid = "f170";
					}else if(rs == 10){
						fid = "f171";
					}else if(rs == 11){
						fid = "f172";
					}else if(rs == 12){
						fid = "f173";
					}
				}else if(y == 10){
					u = u10;
					if(rs == 2){
						fid = "f160";
					}else if(rs == 3){
						fid = "f174";
					}else if(rs == 4){
						fid = "f175";
					}else if(rs == 5){
						fid = "f176";
					}else if(rs == 6){
						fid = "f177";
					}else if(rs == 7){
						fid = "f178";
					}else if(rs == 8){
						fid = "f179";
					}else if(rs == 9){
						fid = "f180";
					}else if(rs == 10){
						fid = "f181";
					}else if(rs == 11){
						fid = "f182";
					}else if(rs == 12){
						fid = "f183";
					}
				}
				
				var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112308584254039229833_1634203729603&fid=" + fid + "&po=" + fx + "&pz=50&pn=1&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m:0+t:6+f:!2,m:0+t:13+f:!2,m:0+t:80+f:!2,m:1+t:2+f:!2,m:1+t:23+f:!2&fields=" + u;				
				$.ajax({
					type: "get",
					url: url,
					dataType: "text",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						writeSource(data);	
					}
				});
				
			}
						
			function writeSource(data) { 			
				//document.write(data);
				data = data.replace(/ /g,"").match(/\"diff\":(\S*)\]\}\}\);/)[1];	
				//data = "{\"data\":" + data + "}]}";
				if(y == 1){
					data = data.replace(/(\{\").*?(?=\})/g,function(word){ 				
						str = word.match(/\{(\S*)/)[1]; 								
						return "{" + str.split(',')[1] + "," +			
						str.split(',')[2] + ","	+						
						str.split(',')[0] + ","	+	 
						str.split(',')[3] + ","	+						
						str.split(',')[12] + "," +	
						str.split(',')[4] + ","	+	 										
						str.split(',')[5] + ","	+	 
						str.split(',')[6] + ","	+
						str.split(',')[7] + ","	+
						str.split(',')[8] + ","	+
						str.split(',')[9] + ","	+
						str.split(',')[10] + ","	+
						str.split(',')[11];
					});	
				}				
				data = data + "]";
				//document.write(data);
				
				var json = JSON.parse(data);				
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var n = 0;
				var b = 0;
				for(var key in json[0]){  //表头
					key = key.replace('f267','3日主力净额').replace('f268','3日主力净占比%').replace('f269','3日超大单净额').replace('f270','3日超大单净占比%');					
					key = key.replace('f271','3日大单净额').replace('f272','3日大单净占比%').replace('f273','3日中单净额').replace('f274','3日中单净占比%');
					key = key.replace('f275','3日小单净额').replace('f276','3日小单净占比%').replace('f127','3日涨幅%');

					key = key.replace('f164','5日主力净额').replace('f165','5日主力净占比%').replace('f166','5日超大单净额').replace('f167','5日超大单净占比%');					
					key = key.replace('f168','5日大单净额').replace('f169','5日大单净占比%').replace('f170','5日中单净额').replace('f171','5日中单净占比%');
					key = key.replace('f172','5日小单净额').replace('f173','5日小单净占比%').replace('f109','5日涨幅%')

					key = key.replace('f174','10日主力净额').replace('f175','10日主力净占比%').replace('f176','10日超大单净额').replace('f177','10日超大单净占比%');					
					key = key.replace('f178','10日大单净额').replace('f179','10日大单净占比%').replace('f180','10日中单净额').replace('f181','10日中单净占比%');
					key = key.replace('f182','10日小单净额').replace('f183','10日小单净占比%').replace('f160','10日涨幅%')

					key = key.replace('f62','主力净额').replace('f184','主力净占比%').replace('f66','超大单净额').replace('f69','超大单净占比%');					
					key = key.replace('f72','大单净额').replace('f75','大单净占比%').replace('f78','中单净额').replace('f81','中单净占比%');
					key = key.replace('f84','小单净额').replace('f87','小单净占比%').replace('f127','3日涨幅%')
					key = key.replace('f12','代码').replace('f14','名称').replace('f3','涨幅%').replace('f2','现价');
					
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);
					if(m == rs){  //高亮
						n = m;
						th.style.color = "#FF6633";	
						if(fx == 0){
							th.style.color = "#ADFF2F";
						}
					}					
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;
					var dm = "";
					var mc = "";
					for(var key in json[i]){ //行元素遍历						
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;						
						}else if(p >= 4 && p%2 == 0){
							rc = NumberTransform(rc);
						}							
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
							
						if(p == n + 1){														
							td.getElementsByTagName("a")[0].style.color = "#FF6633";
							if(fx == 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}
						
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}					
				var div = document.getElementById("towrite");									
				div.appendChild(table);
				table.id = "gg";
				makeSortable(table);
				hover();								
			}
			
			var pt = 0;
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);	
							if(n >= 2){
								if(rs != n){  //切换列 清零
									rs = n;
									fx = 1;
									pt = 1;
								}else{
									fx = (pt%2 == 0) ? 1 : 0;
									pt++;
								}														
								getSource(y);								
							}							
						}
					}(i));
				}
			}
			
		</script>	
	</body>
</html>